package io.vertx.example;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Handler;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.RoutingContext;
import io.vertx.ext.web.handler.BodyHandler;
import io.vertx.ext.web.handler.StaticHandler;

@Component
public class StaticServer extends AbstractVerticle {

  @Autowired
  AppConfiguration configuration;

  @Override
  public void start() throws Exception {
    final Router router = Router.router(vertx);

    // Serve the static pages
    router.route().handler(StaticHandler.create());
    
//
//    router.route().handler(BodyHandler.create());
//    // router.get("/hello")表示所监听URL路径
//    router.get("/hello").handler(new Handler<RoutingContext>() {
//
//        public void handle(RoutingContext event) {
//            event.response().putHeader("content-type", "text/html").end("Hello World");
//        }
//    });
    

    vertx.createHttpServer().requestHandler(router::accept).listen(configuration.httpPort());
  }
}
